import { defineStore } from 'pinia'

import { StoreEnum } from '../enum'

export const useSystemStore = defineStore(StoreEnum.SYSTEM_STORE, {
  persist: true, // 持久化存储
  state: (): Partial<Istate> => ({
    screenWidth: 0, // 屏幕宽度
    screenHeight: 0, // 屏幕高度
    pixelRatio: 0, // 像素比
    statusBarHeight: 0, // 状态栏高度
    safeAreaInsets: 0, // 安全区域
    navBarHeight: 0, // 导航栏高度
    menuRect: {
      width: 0,
      right: 0,
      height: 0,
      left: 0,
      top: 0,
      bottom: 0,
    }, // 菜单区域
  }),
  actions: {
    setState<K extends keyof UserState>(playload: Record<K, UserState[K]>) {
      this.$patch({ ...playload })
    },
  },
})
